package cn.wjdiankong.levideo.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.utils.Const;
import cn.wjdiankong.levideo.utils.UIUtil;
import cn.wjdiankong.levideo.utils.UmengReportUtils;
import cn.wjdiankong.levideo.utils.Utils;

public class AboutMeActivity extends BaseActivity{
	
	private final static String ALL_WX = "编码美丽";
	private final static String ME_WX = "peter_jw212";
	private final static String WEBSITE_URL = "http://www.wjdiankong.cn";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aboutme);
        initView();
        initData();
    }

    public void initView(){
        super.initView();
        TextView website_TxtView = (TextView) findViewById(R.id.website_txt);
        TextView wx_TxtView = (TextView) findViewById(R.id.me_wx_txt);
        wx_TxtView.setText("加作者微信: peter_jw212");
        TextView all_TxtView = (TextView) findViewById(R.id.wx_all_txt);
        all_TxtView.setText("关注微信公众号: 编码美丽");
        setTextViewClick(website_TxtView, WEBSITE_URL);
        setTextViewClick(wx_TxtView, ME_WX);
        setTextViewClick(all_TxtView, ALL_WX);
    }
    
    private void setTextViewClick(TextView txtView, final String str){
    	int len = str.length();
        SpannableString spanText=new SpannableString(txtView.getText());
        spanText.setSpan(new ClickableSpan() {
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor(Const.theme_bg);//设置文件颜色
                ds.setUnderlineText(true);//设置下划线
            }
            @Override
            public void onClick(View view) {
                if(WEBSITE_URL.equals(str)){
                	WebViewActivity.startDefault(AboutMeActivity.this, WEBSITE_URL);
                	UmengReportUtils.report(UmengReportUtils.ABOUTME_WEBSITE);
                }else if(ME_WX.equals(str)){
                	Utils.copyContent(getApplicationContext(), ME_WX);
    				UIUtil.showShortHintToast(getApplicationContext(), "复制成功");
    				UmengReportUtils.report(UmengReportUtils.ABOUTME_COPY_WX_ME);
                }else if(ALL_WX.equals(str)){
                	Utils.copyContent(getApplicationContext(), ALL_WX);
    				UIUtil.showShortHintToast(getApplicationContext(), "复制成功");
    				UmengReportUtils.report(UmengReportUtils.ABOUTME_COPY_WX_ALL);
                }
            }
        }, spanText.length() - len, spanText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        txtView.setHighlightColor(Color.TRANSPARENT); //设置点击后的颜色为透明，否则会一直出现高亮
        txtView.setText(spanText);
        txtView.setMovementMethod(LinkMovementMethod.getInstance());//开始响应点击事件
    }

    protected void initData(){
    	super.initData();
        setTitle("关于作者");
        setLeftImg(R.drawable.back_icon);
    }

    public static void startDefault(Context context){
    	Intent intent = new Intent(context, AboutMeActivity.class);
        context.startActivity(intent);
    }

	@Override
	protected void clickLeftImg() {
		super.clickLeftImg();
		finish();
	}
	
	@Override
	protected String getPageName() {
		return "about_me";
	}

    
}
